package com.zdsoft.blp.zongbuju.shouye.linliquan.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zdsoft.blp.R;
import com.zdsoft.blp.gongyong.API.API;
import com.zdsoft.blp.gongyong.fanhui.FanHuiView;
import com.zdsoft.blp.gongyong.imageFrame.IvFrameView;
import com.zdsoft.blp.gongyong.imageTrans.CircleImage;
import com.zdsoft.blp.gongyong.net.BaseActivity;
import com.zdsoft.blp.gongyong.net.Net;
import com.zdsoft.blp.gongyong.net.NetCallback;
import com.zdsoft.blp.gongyong.xlistview.XListView;
import com.zdsoft.blp.zongbuju.shouye.linliquan.adapter.LLPingLunAdapter;
import com.zdsoft.blp.zongbuju.shouye.linliquan.entity.LinLi;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class XQQZZPActivity extends BaseActivity implements NetCallback{
    private ListView qz_xlv;
    private TextView ershou_name,ershou_date,ershou_title,lianxiren,ershou_content,ershou_dianhua,ershou_pinglun;
    private ImageView ershou_touxiang,pinglun;
    private Intent intent;
    private List<LinLi> list;
    private FanHuiView qz_title;
    private String id,huifuTime,huifuUser,huifuImage,huifuContent;;

    @Override
    protected void init() {
        setContentView(R.layout.linli_qiuzhixiangqing);
//        实例化控件
        qz_xlv = find(R.id.qz_xlv);
        qz_xlv.setFocusable(false);
        ershou_name = find(R.id.ershou_name);
        ershou_date = find(R.id.ershou_date);
        ershou_title = find(R.id.ershou_title);
        ershou_content = find(R.id.ershou_content);
        ershou_dianhua = find(R.id.ershou_dianhua);
        ershou_pinglun = find(R.id.ershou_pinglun);
        lianxiren = find(R.id.lianxiren);
        ershou_touxiang = find(R.id.ershou_touxiang);
        pinglun = find(R.id.pinglun);
        qz_title = find(R.id.qz_title);
//        设置ListView不可滑动
        qz_xlv.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
//        接收数据
        intent = getIntent();
        id = intent.getStringExtra("id");
        String title=intent.getStringExtra("title");
        qz_title.getTv_title().setText(title);
        //实例化Net的方法
        getNet();
        pinglun.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent=new Intent(XQQZZPActivity.this,LLHFActivity.class);
                intent.putExtra("id","5");
                startActivity(intent);
            }
        });
    }
    @Override
    public void onResponse(boolean flag, int code, String res) {
        Log.e("求职详情",res);
        try {
            JSONObject object=new JSONObject(res);
            ershou_date.setText(object.getString("createTime"));
            Picasso.with(this).load(object.getString("headimgurl")).transform(new CircleImage()).into(ershou_touxiang);
            ershou_name.setText(object.getString("userName"));
            ershou_title.setText(object.getString("title"));
            ershou_content.setText(object.getString("content"));
            ershou_dianhua.setText(object.getString("contactPhone"));
            ershou_pinglun.setText(object.getString("replyNum"));
            boolean replySet=object.isNull("replySet");
            if (replySet==false){
                list=new ArrayList<>();
                LinLi pinche=null;
                JSONArray array=object.getJSONArray("replySet");
                for (int i=0;i<array.length();i++){
                    JSONObject obj=array.getJSONObject(i);
                    huifuUser=obj.getString("replyUserName");
                    huifuTime=obj.getString("replyTime");
                    huifuContent=obj.getString("content");
                    huifuImage=obj.getString("replyUserHeadimgurl");
                    pinche=new LinLi(huifuUser,huifuContent,huifuImage,huifuTime);
                    list.add(pinche);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        LLPingLunAdapter adapter = new LLPingLunAdapter(list,getApplicationContext());
        qz_xlv.setAdapter(adapter);
    }

    public void getNet() {
        Net net=new Net();
        net.url= API.INFOEXCHANGE_URL;
        net.nameSpace=API.INFOEXCHANGE_NAMESPACE;
        net.methodName=API.SEARCHJOBCONTENT;//searchJobContent
        Map map=new HashMap();
        map.put("id",id);
        net.parms=map;
        getServer(net,this);
    }
}
